package cz.muni.fi.pb168.eis_web;

import cz.muni.fi.pb138.eis_core.ArtworkManager;
import cz.muni.fi.pb138.eis_core.ArtworkManagerImpl;
import cz.muni.fi.pb138.eis_core.DBTools;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import javax.xml.xquery.XQException;

/**
 * Created with IntelliJ IDEA.
 * User: Dodo
 * Date: 16.5.2012
 * Time: 18:30
 * To change this template use File | Settings | File Templates.
 */

@WebListener
public class StartListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent ev) {

        ServletContext servletContext = ev.getServletContext();
/*
        BeanFactory beanFactory = new XmlBeanFactory(new FileSystemResource("C:\\Users\\Lauro\\Dropbox\\CRUD\\src\\main\\resources\\spring.xml"));

        PictureManager pictureManager = beanFactory.getBean("pictureManager", PictureManagerImpl.class);
*/
        ArtworkManager am = null;
        try
        {
            am = new ArtworkManagerImpl(DBTools.getInstance());
        }
        catch(XQException ex)
        {
            Logger.getLogger(StartListener.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        servletContext.setAttribute("artworkManager", am);

        //categoryManager.createTableCategory();
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

}
